﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using ClassLibrary.DAO;

public partial class MasterPage : System.Web.UI.MasterPage
{
    CategoryParrentDAO menuParrDAO = new CategoryParrentDAO(Global.CONNECTION_STRING);
    CategoryChildDAO menuChildDAO = new CategoryChildDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadMenuParr();
            LoadMenuP_Left();
        }
    }

    // Load Menu Left
    private void LoadMenuP_Left()
    {
        rpMenuLeft.DataSource = menuParrDAO.GetMenuParrent();
        rpMenuLeft.DataBind();
    }

    private void LoadMenuParr()
    {
        rpMenu.DataSource = menuParrDAO.GetMenuParrent();
        rpMenu.DataBind();
    }
    protected void rpMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
          e.Item.ItemType == ListItemType.AlternatingItem)
        {
            //int idCus = ((TblCustomers)Session[Global.SESSION_LOGGED_USER]).CustomerIndex;
            Repeater reChildMenu = (Repeater)e.Item.FindControl("rpMenuChild");
            HiddenField hidIDMenuP = (HiddenField)e.Item.FindControl("hidIDMenuP");
            hidIDMenuP.Value = DataBinder.Eval(e.Item.DataItem, "IDCateParrent").ToString();

            // DataTable dtParentMenu = ParentMenuDAO.GetParentMenuAll(idCus);
            // Lấy menu Cha

            DataTable menuCha = menuParrDAO.GetMenuParrent();

            string id = hidIDMenuP.Value;
            string idMenu = Request.QueryString["id"];
            if (reChildMenu != null)
            {
                reChildMenu.DataSource = menuChildDAO.GetCateChild_ByIDParrent(Global.ConvertToInt(id));
                reChildMenu.DataBind();
            }

        }
    }
    protected void rpMenuLeft_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater reChildMenuLeft = (Repeater)e.Item.FindControl("rpMenuLeftChild");
            HiddenField hidIDMenuPLeft = (HiddenField)e.Item.FindControl("hidMenuLeft");
            hidIDMenuPLeft.Value = DataBinder.Eval(e.Item.DataItem, "IDCateParrent").ToString();

            DataTable menuChaLeft = menuParrDAO.GetMenuParrent();
            string id = hidIDMenuPLeft.Value;
            // string idMenuLeft = Request.QueryString["id"];
            if (reChildMenuLeft != null)
            {
                reChildMenuLeft.DataSource = menuChildDAO.GetCateChild_ByIDParrent(Global.ConvertToInt(id));
                reChildMenuLeft.DataBind();
            }

        }
    }
}
